﻿using DotNetty.Codecs.Http;
using JGSY.NotNetty.ControllerBus.Attributes;
using System.Reflection;

namespace JGSY.NotNetty.ControllerBus
{
    public class ActionInfo
    {
        public MethodInfo Action { get; }

        public ActionInfo(MethodInfo action)
        {
            Action = action;
        }
        /// <summary>
        /// 处理HttpMethodAttribute
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public IFullHttpResponse HandlerMethod(IFullHttpRequest request)
        {
            IFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus.OK);
            var attribute = Action.GetCustomAttribute<HttpMethodAttribute>();
            attribute?.Handler(request, response);
            return response;
        }
    }
}
